#include "stdafx.h"
#include "ModelManager.h"

#include "Model.h"
#include "GraphicsResources.h"
#include "MeshManager.h"
#include "MaterialManager.h"

using namespace mgfx;
using namespace std;

Model * ModelManager::createModel(const string & key)
{
	assert(mModels.find(key) == mModels.end());
	Model * model = new Model;
	mModels[key] = model;
	return model;
}

Model * ModelManager::getModel(const string & key)
{
	assert(mModels.find(key) != mModels.end());
	return mModels[key];
}

void ModelManager::init()
{
	Model * model = createModel("TexturedSphere");
	model->setMesh(GraphicsResources::getGlobal()->getMeshMgr()->getMesh("Sphere"));
	model->setMaterial(GraphicsResources::getGlobal()->getMaterialMgr()->getDefaultMaterial());

	mDefaultModel = model;
}

void ModelManager::deinit()
{
	for(ModelMap::iterator it = mModels.begin() ; it != mModels.end() ; ++it)
		delete it->second;
}